<?php defined('BASEPATH') OR exit('No direct script access allowed');


class Token_model extends Base_model
{
	protected $_table_name = 'admin_token';
    protected $_key_name = 'id';
	
	public function __construct()
    {
        parent::__construct();
		
    }

    public function adds($admin_id = NULL,$out_time = 100)
    {
        if($admin_id == NULL) return false;
        $id = $this->get_token();

        $data_arr["admin_id"] = $admin_id;
        $data_arr["token"] = $id;
        $data_arr["ctime"] = time();
        $data_arr["lutime"] = time();
        $data_arr["extime"] = $data_arr["lutime"] + $out_time;
        if(@$this->insert($data_arr)){
            return $id;
        }
        return false;
    }

    public function dels_token($token = NULL){
	    if($token == NULL) return false;
        return $this->delete(array("token"=>$token));
    }

    public function dels_admin($id = 0){
        if($id == 0) return false;
        return $this->delete(array("admin_id"=>$id));
    }

    public function info($token = NULL){
        if($token == 0) return NULL;
        $this->where("token",$token);
        return $this->row();
    }

    public function edits($token = NULL,$out_time = 100)
    {
        if($token == NULL) return false;

        $this->where("token",$token);
        $data_arr["lutime"] = time();
        $data_arr["extime"] = $data_arr["lutime"] + $out_time;
        return $this->update($data_arr);

    }

    private function get_token()
    {
        return uniqid("",true);
    }

}
/* End of file base_model.php */
/* Location: ./system/application/models/base_model.php */
